﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace INTROSE
{
    public partial class View_Transactions : Form
    {
        SqlConnection con = new SqlConnection("Data Source = .\\SQLEXPRESS; Database = Introse; Integrated Security = True");
        private string name, position;
        private int num;
        public View_Transactions(string name, string position, int a)
        {
            InitializeComponent();
            this.name = name;
            this.position = position;
            this.num = a;
            con.Open();
            SqlCommand command = new SqlCommand("select * from orders where transNo = '" + num + "'", con);
            SqlDataReader reader = command.ExecuteReader();
            if (reader.HasRows)
            {
                reader.Read();
                lblTransNumGen.Text = reader.GetInt32(0).ToString();
                txtDateOrdered.Text = reader.GetDateTime(1).ToString();
                txtName.Text = reader.GetString(2);
                txtDatePaid.Text = reader.GetDateTime(4).ToString();
                txtAddress.Text = reader.GetString(3);
                txtDateClaimed.Text = reader.GetDateTime(7).ToString();
                if (reader.GetBoolean(5) == false)
                    radioButtonUnpaid.Checked = true;
                else
                    radioButtonPaid.Select();
                if (reader.GetBoolean(9) == false)
                {
                    radioButtonPickUp.Checked = true;
                    if (reader.GetBoolean(8) == false)
                        radioButtonUnclaimed.Checked = true;
                    else
                    {
                        radioButtonClaimed.Checked = true;
                    }
                }
                else
                {
                    radioButtonDelivery.Checked = true;
                    if (reader.GetBoolean(6) == false)
                        radioButtonUnclaimed.Checked = true;
                    else
                    {
                        radioButtonClaimed.Checked = true;
                    }
                }
            }
            reader.Close();
            SqlCommand command1 = new SqlCommand("select * from orderItems where transNo = '" + num + "'", con);
            SqlDataReader reader1 = command1.ExecuteReader();
            if (reader1.HasRows)
            {
                reader1.Read();
                txt100cc.Text = reader1.GetInt32(1).ToString();
                txtp100cc.Text = reader1.GetInt32(6).ToString();
                txtTotal.Text = reader1.GetInt32(11).ToString();
                if (txt100cc.Text != "0")
                    chckBox100cc.Checked = true;
                else
                {
                    txt100cc.Enabled = false;
                    txtp100cc.Enabled = false;
                }
                txt200cc.Text = reader1.GetInt32(2).ToString();
                txtp200cc.Text = reader1.GetInt32(7).ToString();
                if (txt200cc.Text != "0")
                    chckBox200cc.Checked = true;
                else
                {
                    txt200cc.Enabled = false;
                    txtp200cc.Enabled = false;
                }
                txt250cc.Text = reader1.GetInt32(3).ToString();
                txtp250cc.Text = reader1.GetInt32(8).ToString();
                if (txt250cc.Text != "0")
                    chckBox250cc.Checked = true;
                else
                {
                    txt250cc.Enabled = false;
                    txtp250cc.Enabled = false;
                }
                txt400cc.Text = reader1.GetInt32(4).ToString();
                txtp400cc.Text = reader1.GetInt32(9).ToString();
                if (txt400cc.Text != "0")
                    chckBox400cc.Checked = true;
                else
                {
                    txt400cc.Enabled = false;
                    txtp400cc.Enabled = false;
                }
                txt500cc.Text = reader1.GetInt32(5).ToString();
                txtp500cc.Text = reader1.GetInt32(10).ToString();
                if (txt500cc.Text != "0")
                    chckBox500cc.Checked = true;
                else
                {
                    txt500cc.Enabled = false;
                    txtp500cc.Enabled = false;
                }
            }
            reader1.Close();
            SqlCommand command2 = new SqlCommand("SELECT * FROM sizes WHERE size = '100cc'", con);
            SqlDataReader reader2 = command2.ExecuteReader();
            if (reader2.HasRows)
            {
                reader2.Read();
                txtp100cc.Text = reader2.GetInt32(1).ToString();
            }
            reader2.Close();
            command2 = new SqlCommand("SELECT * FROM sizes WHERE size = '200cc'", con);
            reader2 = command2.ExecuteReader();
            if (reader2.HasRows)
            {
                reader2.Read();
                txtp200cc.Text = reader2.GetInt32(1).ToString();
            }
            reader2.Close();
            command2 = new SqlCommand("SELECT * FROM sizes WHERE size = '250cc'", con);
            reader2 = command2.ExecuteReader();
            if (reader2.HasRows)
            {
                reader2.Read();
                txtp250cc.Text = reader2.GetInt32(1).ToString();
            }
            reader2.Close();
            command2 = new SqlCommand("SELECT * FROM sizes WHERE size = '400cc'", con);
            reader2 = command2.ExecuteReader();
            if (reader2.HasRows)
            {
                reader2.Read();
                txtp400cc.Text = reader2.GetInt32(1).ToString();
            }
            reader2.Close();
            command2 = new SqlCommand("SELECT * FROM sizes WHERE size = '500cc'", con);
            reader2 = command2.ExecuteReader();
            if (reader2.HasRows)
            {
                reader2.Read();
                txtp500cc.Text = reader2.GetInt32(1).ToString();
            }
            con.Close();
            reader2.Close();
        }

        private void DateClaimed_Click_1(object sender, EventArgs e)
        {

        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
            View_Transactions_Tabbed view = new View_Transactions_Tabbed(name, position);
            view.Show();
        }

        private void View_Transactions_Load(object sender, EventArgs e)
        {
            txt100cc.Enabled = false;
            txt200cc.Enabled = false;
            txt250cc.Enabled = false;
            txt400cc.Enabled = false;
            txt500cc.Enabled = false;
            txtAddress.Enabled = false;
            txtDateClaimed.Enabled = false;
            txtDateOrdered.Enabled = false;
            txtDatePaid.Enabled = false;
            txtName.Enabled = false;
            txtp100cc.Enabled = false;
            txtp200cc.Enabled = false;
            txtp250cc.Enabled = false;
            txtp400cc.Enabled = false;
            txtp500cc.Enabled = false;
            txtTotal.Enabled = false;
            chckBox100cc.Enabled = false;
            chckBox200cc.Enabled = false;
            chckBox250cc.Enabled = false;
            chckBox400cc.Enabled = false;
            chckBox500cc.Enabled = false;
            radioButtonClaimed.Enabled = false;
            radioButtonDelivery.Enabled = false;
            radioButtonPaid.Enabled = false;
            radioButtonPickUp.Enabled = false;
            radioButtonUnclaimed.Enabled = false;
            radioButtonUnpaid.Enabled = false;
        }
    }
}
